<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>在线投票系统</title>
<base href="../">
<link type="image/x-icon" href="images/yc.png" rel="shortcut icon"/>
<link type="text/css" rel="stylesheet" href="css/style.css" />
<link type="text/css" rel="stylesheet" href="blue/doubleDate.css" />
<script type="text/javascript">
var isIE = !!document.all;
function AddOption()
{
	var voteoptions = document.getElementById("voteoptions");
	var _p = document.createElement("p");
	var _input = document.createElement("input");
	_input.type = "text";
	_input.className = "input-text";
	_input.setAttribute("name", "options");
	_p.appendChild(_input);
	var _a = document.createElement("a");
	_a.className = "del";
	_a.setAttribute("href", "javascript:;");
	if(isIE) {
		_a.attachEvent("onclick", DelOption);
	} else {
		_a.addEventListener("click", DelOption, false);
	}
	_a.appendChild(document.createTextNode("删除"));
	_p.appendChild(_a);
	voteoptions.appendChild(_p);
}
function DelOption(e)
{
	if(!e) e = window.event;
	var a = e.srcElement || e.target;
	var obj = a.parentNode;
	obj.parentNode.removeChild(obj);
}
</script>
</head>
<body>


 
<div id="header" class="wrap">
	<img src="images/logo.gif" />
</div>
<div id="navbar" class="wrap">
	<div class="profile">
		<b v-if="loginStatus">您好，{{user.uname}}</b>
		<b v-else><a href="login.html">请先登录</a></b>
		<span class="return"><a href="back/view.html">返回列表</a></span>
		<span class="addnew"><a href="back/add.html">添加新投票</a></span>
		<span class="modify"><a href="manage.html">维护</a></span>	
	</div>
	<div class="search">
		<form method="post" action="">
			<input type="text" name="keywords" class="input-text" value=""/><input type="submit" name="submit" class="input-button" value="" />
		</form>
	</div>
</div>

<div id="voteManage" class="box">
	<h2>添加新投票</h2>
	<div class="content">
	<form onsubmit="return add()" id="myform">
			<dl>
				<dt>投票内容：</dt>
				<dd>
				   <input type="text" class="input-text" name="title"  id="title"/>
				</dd>
				<dt>投票类型：</dt>
				<dd>
		  		   <input type="radio" name="type"  checked="checked" value="1" />单选
				   <input type="radio" name="type" value="2" />多选
				</dd>
				<dt>开始日期：</dt>
				<dd>
				   <input type="text" name="startDate" id="sdate" class="doubledate ipticon" readonly="readonly"/>
				   至  <input type="text" name="endDate" id="edate" class="doubledate ipticon" readonly="readonly"/>
				</dd>

				<dt>投票选项：</dt>
				<dd id="voteoptions">
					<p><input type="text" class="input-text" name="options" /></p>
					<p><input type="text" class="input-text" name="options" /></p>
				</dd>
				
				
				<dt></dt>
				<dd class="button">
					<input type="image" src="images/button_submit.gif"  />
					<a href="javascript:;" onclick="AddOption()">增加选项</a>
					<a href="Subject!list.action">取消操作</a>
				</dd>
			</dl>
		</form>
	</div>
</div>
<div id="footer" class="wrap">
	源辰信息 &copy; 版权所有
</div>

<script type="text/javascript" src="js/jquery-1.12.4.js"></script>
<script type="text/javascript" src="js/doubleDate2.0.js"></script>
<script type="text/javascript" src="js/vue.js"></script>
<script type="text/javascript" src="js/axios.js"></script>
<script type="text/javascript" src="js/qs.js"></script>
<script type="text/javascript" src="js/check.js"></script>
<script type="text/javascript">
	$(function(){
		$('.doubledate').kuiDate({
			className:'doubledate',
			isDisabled: "0"  // isDisabled为可选参数，“0”表示今日之前不可选，“1”标志今日之前可选
		});
	});
	
function add(){
	let title = $.trim($("#title").val());
	let types = $("#myform input[name='type']:checked").val();
	let sdate = $.trim($("#sdate").val());
	let edate = $.trim($("#edate").val());
	let options = [];
	$("#voteoptions input").each(function(index , item){
		options.push(item.value);
	})
	if(title == "" || options.length <=0 || sdate == "" || edate == ""){
		return false;
	}
	
	let obj = {tname:title, types: types, sdate: sdate, edate: edate, uname: options.join("$")};
	$.post("topic/add",obj,rt =>{
		if(rt.code == 200){
			$("#myform")[0].reset();
			alert("添加成功。。。");
			return false;
		}
		
		if(rt.code == 600){
			alert("请先登录。。。");
			location.href="login.html";
			return false;
		}
		alert("添加失败。。。");
		
	},"json");
	return false;
}



</script>
</body>
</html>

